package com.zyq.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zyq.common.entity.AclRole;
import com.zyq.common.vo.Result;
import com.zyq.system.service.AclRoleService;
import com.zyq.system.vo.FenUserRoleVo;
import com.zyq.system.vo.RoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system/role")
@Api(tags = "角色查询")
public class AclRoleController {
    @Autowired
    private AclRoleService aclRoleService;


    @ApiOperation(value = "角色分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "第几页",name = "currentPage"),
            @ApiImplicitParam(value = "这页的总条数",name = "pageSize"),
            @ApiImplicitParam(value = "分页条件",name = "roleVo")
    })
    @PostMapping("/findRoleByPage/{currentPage}/{pageSize}")
    public Result<IPage<AclRole>> findRoleByPage(@PathVariable Integer currentPage,
                                                 @PathVariable Integer pageSize,
                                                 @RequestBody RoleVo roleVo
                                                ){
        return aclRoleService.findRoleByPage(currentPage,pageSize,roleVo);
    }

    @GetMapping("/findRoleByUserId/{userId}")
    public Result<Map<String,Object>> findRoleByUserId(@PathVariable("userId") String userId){
        return aclRoleService.findRole(userId);
    }

    // 给当前用户进行角色分配
    @PostMapping("fenUserRole")
    public Result<String> fenUserRole(@RequestBody FenUserRoleVo fenUserRoleVo){
        return aclRoleService.fenUserRole(fenUserRoleVo);
    }
}
